<?php

require('header.php');
require('table_des_matieres.php');
	
echo '	<fieldset>
			<legend>'.$language[$_SESSION['lang']]["Goods"].'</legend>

			<form method="POST">
				<select name="good">';

				foreach ($goods as $good)
				{
					
					echo '<option value="'.$good->id_bien.'">'.$good->nom.'</option>';
					
				}

echo '			</select>

				<input type="submit" name="selectgood" value="'.$language[$_SESSION['lang']]["Valid"].'">

			</form>

		</fieldset>';
		
if (isset($_POST["good"]))
{
	
	if (isset($_GET["people"]))
	{
	
		echo '	<fieldset>
					<legend>'.$good->nom.'</legend>';
		
			if (!empty($locations))
			{
		
				foreach ($locations as $location)
				{
					echo $location->civilite." ".$location->nom." ".$location->prenom." (".$location->login.") ".$language[$_SESSION['lang']]["Startingthe"]." ".$location->date_debut." ".$language[$_SESSION['lang']]["For"]." ".$location->duree." ".$language[$_SESSION['lang']]["Days"]."<br />";
				}
			
			}
			else
			{
				
				echo $language[$_SESSION['lang']]["NothingToDisplay"];
				
			}
		
		echo '	</fieldset>';
	
	}
	else if (isset($_GET["prices"]))
	{
		
		echo '	<fieldset>
					<legend>'.$good->nom.'</legend>';
					
		echo '	<table class="locationtable">
					<tr>
						<th>'.$language[$_SESSION['lang']]["BeginningDate"].'</th>
						<th>'.$language[$_SESSION['lang']]["Duration"].'</th>
						<th>'.$language[$_SESSION['lang']]["Price"].'</th>
						<th>'.$language[$_SESSION['lang']]["TOC_specialoffers"].'</th>
					</tr>';
		
			if (!empty($locations))
			{
		
				foreach ($locations as $location)
				{
					if ($location->etat == "0")
					{
						
						echo '<tr><form method="POST">';
						echo '<td>'.$location->date_debut.'</td>';
						echo '<td>'.$location->duree.' '.$language[$_SESSION['lang']]["Days"].'</td>';
						
						if (isset($_POST["changePrice"]))
						{
							echo '	<td>
										<input type="text" name="price" value="'.$location->prix.'" style="direction:rtl;"> €
										<input type="submit" name="validPrice" value="'.$language[$_SESSION['lang']]["Valid"].'">
									</td>';
						}
						else
						{
							echo '<td>'.$location->prix.' €</td>';
						}
						
						if (isset($_POST["changePromo"]))
						{
							echo '	<td>
										<input type="text" name="promo" value="'.$location->promo.'" style="direction:rtl;"> €
										<input type="submit" name="validPromo" value="'.$language[$_SESSION['lang']]["Valid"].'">
									</td>';
						}
						else
						{
							echo '<td>'.$location->promo.' €</td>';
						}
						
						echo '	<td>
									<input type="hidden" name="good" value="'.$_POST["good"].'">
									<input type="hidden" name="location" value="'.$location->id_location.'">
									<input type="submit" name="changePrice" value="'.$language[$_SESSION['lang']]["ChangePrice"].'">
									<input type="submit" name="changePromo" value="'.$language[$_SESSION['lang']]["ChangePromo"].'">
								</td>';
						
						echo '</form></tr>';
					}
				}
			
			}
			else
			{
				
				echo $language[$_SESSION['lang']]["NothingToDisplay"];
				
			}
		
		echo '	</table>';
		echo '	</fieldset>';
		
	}
	else
	{
		echo '	<fieldset>
					<legend>'.$good->nom.'</legend>
					<form method="POST" action="ajouterlocation.php">
						<input type="hidden" name="good" value="'.$_POST["good"].'">
						<input type="submit" name="addLocation" value="'.$language[$_SESSION['lang']]["AddLocation"].'">
					</form>';
		
					echo '	<table class="locationtable">
					<tr>
						<th>'.$language[$_SESSION['lang']]["BeginningDate"].'</th>
						<th>'.$language[$_SESSION['lang']]["Duration"].'</th>
						<th>'.$language[$_SESSION['lang']]["Price"].'</th>
						<th>'.$language[$_SESSION['lang']]["TOC_specialoffers"].'</th>
						<th></th>
					</tr>';
		
			if (!empty($locations))
			{
		
				foreach ($locations as $location)
				{
					if ($location->etat == "0")
					{
						
						echo '<tr><form method="POST">';
						echo '<td>'.$location->date_debut.'</td>';
						echo '<td>'.$location->duree.' '.$language[$_SESSION['lang']]["Days"].'</td>';
						echo '<td>'.$location->prix.' €</td>';	
						echo '<td>'.$location->promo.' €</td>';
						echo '	<td>
									<input type="hidden" name="good" value="'.$_POST["good"].'">
									<input type="hidden" name="location" value="'.$location->id_location.'">
									<input type="submit" name="delete" value="'.$language[$_SESSION['lang']]["DeleteLocation"].'">
								</td>';
						
						echo '</form></tr>';
					}
				}
			
			}
		
		echo '	</table>';
		
		echo '	</fieldset>';
	
	}
	
}

require('footer.php');

?>
